<?php

namespace globalunit\model;

use globalunit\model\RedisPOB;
use QYS\Util\Debug;
use QYS\Core\Config as CoreConfig;
use globalunit\utils\Config;
use QYS\Log\Log;

class UserModel extends BaseModel
{
    public $id              = 0;       // 主键
    public $phone           = "";       // 手机号
    public $sex             = 0;
    public $nickname        = "";
    public $avatar          = "";
    public $organize_id     = "";
    public $appid           = "";
    public $pfid            = "";
    public $wid             = 0;
    public $is_login        = 0;
    public $last_login_time = "";   //最后登录时间
    public $last_get_star_time = "";  //最后获取星星时间
    public $online_status   = 0;
    public $star_num        = 0;
    public $score           = 0;
    public $created_at      = "";
    public $updated_at      = "";
    public $deleted_at      = "";

    public function __construct()
    {
        parent::__construct('yyz_user');
    }

    public function save($except = [])
    {
        if ($this->id > 0) {
            $this->updated_at = date("Y-m-d H:i:s");
            return parent::save();
        }
    }

    public function insert()
    {
        $this->created_at = date("Y-m-d H:i:s");
        return parent::insert();
    }

    public function addstar()
    {
        if ($this->id > 0) {
            $this->star_num = $this->star_num + 1;
            $this->last_get_star_time = date("Y-m-d H:i:s");
            $this->updated_at = date("Y-m-d H:i:s");
            return parent::save();
        }
    }


    public function descstar($num)
    {
        if ($this->id > 0) {
            $this->star_num = max(0, $this->star_num - $num);
            $this->updated_at = date("Y-m-d H:i:s");
            return parent::save();
        }
    }

    public function cleanstar()
    {
        if ($this->id > 0) {
            $this->star_num = 0;
            $this->updated_at = date("Y-m-d H:i:s");
            return parent::save();
        }
    }

    public function toArray()
    {
        $a = parent::toarray();
        return $a;
    }
}
